home *** CD-ROM | disk | FTP | other *** search
/ CD-ROM Windows Selection / Windows Selection 1.iso / Programmer's Utilities / Freeman Installer / fpath.h < prev    next >
Encoding:
C/C++ Source or Header  |  1997-04-10  |  4.4 KB  |  255 lines

  1. #define __FPATH_H
  2.  
  3.  
  4. #ifndef __IO_H
  5. #include "io.h"
  6. #endif
  7. #ifndef __DOS_H
  8. #include "dos.h"
  9. #endif
  10. #ifndef __STRING_H
  11. #include "string.h"
  12. #endif
  13. #ifndef __DSTRING_H
  14. #include "dstring.h"
  15. #endif
  16.  
  17.  
  18. #undef enable             /* we don't need the macro enable & disable in dos.h */
  19.  
  20. #undef disable
  21.  
  22.  
  23. #ifdef _MSC_VER                                                   /* microsoft */
  24. #undef  isborland
  25. #else                                                               /* borland */
  26. #define isborland
  27. #endif
  28.  
  29.  
  30. #ifdef isborland                          /* we need MAXPATH and etc and rmdir */
  31.  
  32. #ifndef __DIR_H
  33. #include "dir.h"
  34. #endif
  35.  
  36. #else
  37.  
  38. #ifndef __DIRECT_H
  39. #include "direct.h"
  40. #endif
  41.  
  42. #ifndef __STDLIB_H
  43. #include "stdlib.h"
  44. #endif
  45.  
  46. #define MAXPATH  _MAX_PATH
  47. #define MAXDRIVE _MAX_DRIVE
  48. #define MAXDIR   _MAX_DIR
  49. #define MAXFILE  _MAX_FNAME
  50. #define MAXEXT   _MAX_EXT
  51.  
  52. #endif
  53.  
  54.  
  55. struct ffbuf:public WIN32_FIND_DATA
  56. {
  57.    HANDLE h;
  58. };
  59.  
  60. typedef unsigned int UINT;
  61.  
  62.  
  63. class varpath;
  64.  
  65.  
  66. class abspath                                                 /* abstract path */
  67. {
  68.    public:
  69.  
  70.    enum
  71.    {
  72.       maxpath = MAXPATH, maxdrive = MAXDRIVE, maxdir = MAXDIR,
  73.       maxfile = MAXFILE, maxext   = MAXEXT
  74.    };
  75.  
  76.    virtual char *getbuf() = 0;
  77.  
  78.    operator char*()
  79.    {
  80.       return getbuf();
  81.    }
  82.    char operator[](int i)
  83.    {
  84.       return getbuf()[i];
  85.    }
  86.    int del();
  87.    int chdir();
  88.    int mkdir();
  89.    int rmdir();
  90.    int chkdll();
  91.    int chsize(long l);
  92.    int access(int amode);
  93.    int rename(abspath &x);
  94.    int chkroot();
  95.    int chkexist();
  96.    int chkcanwrite();
  97.    int chkdiroccupied();
  98.    int multimkdir();
  99.    int getdad(varpath *dad);
  100.    int getr(varpath *r);
  101.    int getd(varpath *d);
  102.    int getf(varpath *f);
  103.    int tostd(varpath *path);
  104.    int gettime(SYSTEMTIME *ft);
  105.    int settime(SYSTEMTIME &ft);
  106.    int chksame(abspath &x);
  107.    int comparetime(abspath &y);
  108.    int setfileattr(DWORD flags);
  109.    int getfileattr(DWORD *flags);
  110.    int findfrst(ffbuf *b);
  111.    int findnext(ffbuf *b);
  112.    int findclse(ffbuf *b);
  113.    void get(char path[]);
  114.    void getf(char f[]);
  115.    long getsize();
  116.    long locatestr(char s[]);
  117.    char *chkinc(abspath &x);
  118.  
  119.    static int gethftime(HANDLE h, SYSTEMTIME *ft);
  120.    static int sethftime(HANDLE h, SYSTEMTIME &ft);
  121. };
  122.  
  123. class conpath;
  124.  
  125. class varpath:public abspath                                  /* variable path */
  126. {
  127.    public:
  128.  
  129.    virtual int set(char b[]) = 0;
  130.  
  131.    int tostd()
  132.    {
  133.       return abspath::tostd(this);
  134.    }
  135.    int setcwd();
  136.    int gethome();
  137.    int setroot(int drv);
  138.    int setrootsl(int drv);
  139.    int setdirwin();
  140.    int setdirsys();
  141.    int setbackup(abspath &path);
  142.    int setfmt(char fmt[], ...);
  143.    int merge(char d[], char f[]);
  144.    int merge(abspath &d, abspath &f);
  145.    int rplfile(char f[]);
  146.    int rplfile(abspath &f);
  147.    int setext(char newext[]);
  148.    int setlastc(char c);
  149.    int tmpindir(abspath &d, char prefix[]);
  150.    int tmpinsamedir(abspath &path, char prefix[]);
  151.    #ifdef WIN32
  152.    int tolp();
  153.    int tosp();
  154.    int tolfn();
  155.    int tosfn();
  156.    int setdircom();
  157.    #endif
  158. };
  159.  
  160. class dynpath:public varpath                 /* variable path with dynamic buf */
  161. {
  162.    dstring s;
  163.  
  164.    public:
  165.  
  166.    dynpath()
  167.    {
  168.  
  169.    }
  170.    dynpath(char b[])
  171.    {
  172.       set(b);
  173.    }
  174.    int set(char b[])
  175.    {
  176.       return s.set(b);
  177.    }
  178.    int set(int n)
  179.    {
  180.       return s.set(n);
  181.    }
  182.    int getlen()
  183.    {
  184.       return s.getlen();
  185.    } 
  186.    char *getbuf()
  187.    {
  188.       return s;
  189.    }
  190. };
  191.  
  192. class borpath:public varpath                /* variable path with borrowed buf */
  193. {
  194.    char *s;                                 /* the buffer must be large enough */
  195.  
  196.    public:
  197.  
  198.    borpath(char sx[])
  199.    {
  200.       s = sx;
  201.    }
  202.    int set(char b[])
  203.    {
  204.       strcpy(s, b);
  205.  
  206.       return 1;
  207.    } 
  208.    char *getbuf()
  209.    {
  210.       return s;
  211.    }
  212. };
  213.  
  214. class stcpath:public varpath                  /* variable path with static buf */
  215. {
  216.    char s[maxpath];
  217.  
  218.    public:
  219.  
  220.    stcpath()
  221.    {
  222.       s[0] = '\0';
  223.    }
  224.    stcpath(char b[])
  225.    {
  226.       set(b);
  227.    }
  228.    int set(char b[])
  229.    {
  230.       strcpy(s, b);
  231.  
  232.       return 1;
  233.    } 
  234.    char *getbuf()
  235.    {
  236.       return s;
  237.    }
  238. };
  239.  
  240. class conpath:public abspath                     /* constant (invariable) path */
  241. {
  242.    char *s;
  243.  
  244.    public:
  245.  
  246.    conpath(char b[])
  247.    {
  248.       s = b;
  249.    }
  250.    char *getbuf()
  251.    {
  252.       return s;
  253.    }
  254. };
  255.